//
//  MapTopView.m
//  GaoMapDemo
//
//  Created by wayfor on 17/3/8.
//  Copyright © 2017年 wayfor. All rights reserved.
//

#import "MapTopView.h"
#import <CoreLocation/CoreLocation.h>

@implementation MapTopView


+ (MapTopView *)instanceDatePickerView
{
    NSArray *nibView = [[NSBundle mainBundle] loadNibNamed:@"MapTopView" owner:nil options:nil];
    
    return [nibView objectAtIndex:0];
}

//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        [self awakeFromNib];
//    }
//    return self;
//}


- (void)awakeFromNib{
    [super awakeFromNib];
    
        
    self.backgroundColor = [UIColor clearColor];
//    NSLog(@"%@",_model.LocationDistance);

    
    
//    self.addressLab.text = _model.LocationAddress;
//    self.distanceLab.text = [NSString stringWithFormat:@"%@",_model.LocationDistance];
//    NSLog(@"%@",_model.LocationDistance);
//    if ([_model.LocationTime integerValue] > 0) {
//        NSInteger min = ([_model.LocationTime integerValue]/60);
//        self.timeLab.text = [NSString stringWithFormat:@"%ld",min];
//    }
    
}

-(void)setModel:(LocationModel *)model
{
    _model = model;
    
//    [self.model addObserver:self forKeyPath:@"LocationDistance" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];

//    [self awakeFromNib];
    
//    for (UIView *view in self.subviews) {
//        [view removeFromSuperview];
//    }
    
    self.addressLab.text = model.LocationAddress;
    self.distanceLab.text = [NSString stringWithFormat:@"%@",model.LocationDistance];
    if ([model.LocationTime integerValue] > 0) {
        NSInteger min = ([model.LocationTime integerValue]/60);
        if (min < 1) {
            self.timeLab.text = [NSString stringWithFormat:@"%ld",[model.LocationTime integerValue]];
            self.timdDanWeiLab.text = @"秒";
        }else{
            self.timeLab.text = [NSString stringWithFormat:@"%ld",min];
            self.timdDanWeiLab.text = @"分钟";

        }
    }


}

/*--
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"LocationDistance"] && object == self.model) {
        self.addressLab.text = _model.LocationAddress;
        self.distanceLab.text = [NSString stringWithFormat:@"%@",[change valueForKey:@"new"]];
        NSLog(@"%@",_model.LocationDistance);
        if (_model.LocationTime > 0) {
            NSInteger min = ([_model.LocationTime integerValue]/60);
            self.timeLab.text = [NSString stringWithFormat:@"%ld",min];
        }
    }
}
*/

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
